package com.nuc.bigdata.api.controller;

import com.nuc.bigdata.annotation.ResponseResult;
import com.nuc.bigdata.app.service.ShopCarService;
import com.nuc.bigdata.feign.dto.ShopCarGoodsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackLuo
 * @date 2019/12/5
 */
@RestController
@RequestMapping("/front")
@CrossOrigin
public class ShopCarController {
    private final ShopCarService carService;

    @Autowired
    ShopCarController(ShopCarService carService) {
        this.carService = carService;
    }

    @GetMapping("/car/{userId}")
    @ResponseResult
    public Object queryByUserId(@PathVariable("userId")String userId) {
        return carService.queryCarFeignByUserId(userId);
    }

    @PostMapping("/car/{userId}/goods")
    @ResponseResult
    public Object addGoodsIntoCar(ShopCarGoodsDto goodsDto,
                                @PathVariable("userId")String userId) {
        carService.addGoodsIntoCar(goodsDto, userId);
        return null;
    }

//    @DeleteMapping("/car/{userId}/goods/{commodityId}")
    @GetMapping("/car/{userId}/goods/{commodityId}")
    @ResponseResult
    public Object removeGoodsFromCar(@PathVariable("commodityId")String commodityId,
                                          @PathVariable("userId")String userId) {
        carService.removeGoodsFromCar(commodityId, userId);
        return null;
    }

    @ResponseResult
    @GetMapping("/car/{userId}/goods/{commodityId}/quantity/{quantity}")
    public Object updateGoodsInCar(@PathVariable("commodityId")String commodityId,
                          @PathVariable("userId")String userId,
                          @PathVariable("quantity")Long quantity){
        carService.updateGoodsInCar(commodityId, userId, quantity);
        return null;
    }

    @ResponseResult
    @PostMapping("/car/{userId}/goods/{commodityId}/selected")
    public Object updateGoodsSelectedInCar(@PathVariable("commodityId")String commodityId,
                                   @PathVariable("userId")String userId,
                                   Boolean selected){
        carService.updateGoodsSelectedCar(commodityId, userId, selected);
        return null;
    }
}
